<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/14
 * Time: 10:02
 */

namespace app\admin\controller;


use app\admin\controller\common\Admin;
use think\Db;

class System extends Admin
{
    #系统日志
    public function index()
    {
        if (request() ->isAjax()) {
            #刷选条件
            $wh['ri.id'] = ['>',0];
            if(!empty($_POST['ip'])){
                $wh['ri.ip'] = ['=',$_POST['ip']];
            }
            if(!empty($_POST['text'])){
                $wh['ri.text'] = ['like',"%{$_POST['text']}%"];
            }
            //每页显示几条
            $pag = 30;
            $_POST['index']+=1;
            //return var_dump($wh);
            #返回内容
            $data =  Db::table('q_journal')
                    ->alias('ri')
                    ->join('bg_admin admin','ri.admin_id = admin.id')
                    ->field("
                    ri.id as riid,/*日志id*/
                    ri.ip as riip,/*ip*/
                    ri.new_time as rinew_time,/*时间*/
                    ri.text as ritext,/*详细*/
                    admin.name as adminname/*管理员名称*/
                    ")
                    ->where($wh)
                    ->page("{$_POST['index']},{$pag}")
                    ->order('ri.id desc')
                    ->select();
            $count = Db::table('q_journal')
                ->alias('ri')
                ->where($wh)->count();
            return [$data,$count];
        }
        return view('');
    }
}